﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GWMergeTerminal.STD
{
   public static class CommonHelper
    {
        /// <summary>
        /// 根据字段名获取值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public static object GetValue<T>(this T t, string fieldName)
        {
            try
            {
                if (t != null)
                {
                    var value = t.GetType().GetProperty(fieldName).GetValue(t, null);
                    return value ?? "";
                }
            }
            catch (Exception)
            {
                throw;
            }
            return null;
        }
    }
}
